//
//  ScmRepairTableViewController.m
//  FineNurse
//
//  Created by TT_UED on 2018/4/20.
//  Copyright © 2018年 TT_UED. All rights reserved.
//

#import "ScmRepairTableViewController.h"
#import <Masonry.h>

@interface ScmRepairTableViewController ()

@property(nonatomic ,strong) NSArray* tableViewData;
@property(nonatomic ,strong) NSMutableArray* tableViewDataSubtitle;
@property(nonatomic ,strong) NSMutableArray* tableViewDataSubtitleId;
@property(nonatomic ,strong) NSMutableArray* tableViewDataShowTextview;

@end

@implementation ScmRepairTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"测试"];
    
    [self loadConfigWithUrl];
    [self initTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initTableView{
    
    self.tableViewData = @[@"申请科室",@"维修大类",@"科室地址",@"故障描述",@"紧急程度",@"联系人",@"联系电话",@"送修标志",@"报修地址",@"报修详细地址",@"申请人",@"申请时间",@"说明"];
    
    self.tableViewDataSubtitle = [[NSMutableArray alloc]init];
    self.tableViewDataSubtitleId = [[NSMutableArray alloc]init];
    self.tableViewDataShowTextview = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.tableViewData.count; i++) {
        NSString *title = self.tableViewData[i];
        
        [self.tableViewDataSubtitle addObject:@""];
        [self.tableViewDataSubtitleId addObject:@""];
        
        if([title isEqual:@"报修详细地址"]){
            [self.tableViewDataShowTextview addObject:@"1"];
        }else{
            [self.tableViewDataShowTextview addObject:@"0"];
        }
        
    }
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [[UIView alloc]init];
    
    self.refreshControl = [[UIRefreshControl alloc] init];
    self.refreshControl.tintColor = UIColor.greenColor;
    [self.refreshControl addTarget:self action:@selector(downloadData) forControlEvents:UIControlEventValueChanged];
}

-(void) loadConfigWithUrl{
    
    
    
}

- (IBAction)downloadData {
    [self.refreshControl endRefreshing];
}

#pragma mark tableView 方法


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString * ID = @"ChecklizdvdzfbdzbstItem";
    UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:ID ];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
        
         if([self.tableViewDataShowTextview[indexPath.row] isEqual:@"0"]){

            cell.textLabel.text = self.tableViewData[indexPath.row];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.detailTextLabel.text = self.tableViewDataSubtitle[indexPath.row];
        
         }
        
        if([self.tableViewDataShowTextview[indexPath.row] isEqual:@"1"]){
            
             UIEdgeInsets padding = UIEdgeInsetsMake(10, 14, 10, 10);
            
            UILabel *lbl = [[UILabel alloc]init];
            [cell.contentView addSubview:lbl];
            lbl.textColor = UIColor.blackColor;
            lbl.text = self.tableViewData[indexPath.row];
            
            [lbl mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell.mas_left).offset(padding.left);
                make.top.equalTo(cell.mas_top).offset(padding.top);
                make.right.equalTo(cell.mas_right).offset(-padding.right);
                make.height.mas_equalTo(10);
            }];
            
            UITextView *txt  = [[UITextView alloc]init];
            txt.layer.borderColor = UIColor.grayColor.CGColor;
            txt.layer.borderWidth = 1;
            txt.layer.cornerRadius = 5.0;
            [cell.contentView addSubview:txt];
            
            
            [txt mas_makeConstraints:^(MASConstraintMaker *make) {
                //make.edges.equalTo(cell).with.insets(padding);
                make.top.equalTo(lbl.mas_bottom).offset(10);
                make.left.equalTo(cell.mas_left).offset(padding.left);
                make.bottom.equalTo(cell.mas_bottom).offset(-padding.bottom);
                make.right.equalTo(cell.mas_right).offset(-padding.right);
            }];
        }
        
        
    }
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.tableViewData.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *showTextView = self.tableViewDataShowTextview[indexPath.row];
    if([showTextView isEqual:@"1"]){
        return 120;
    }
    
    return 50;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.row) {
        case 0:
            [self selectDept: indexPath];
            break;
            
        default:
            break;
    }
    
}

-(void)selectDept:(NSIndexPath*)indexPath {
//    LedgerEditDepartViewController *deptview = [[LedgerEditDepartViewController alloc]init];
//
//
//    deptview.getBlock = ^(NSArray *array){
//        if(array.count > 0)
//        {
//            NSDictionary *dict = array[0];
//            NSString *deptName = [dict objectForKey:@"depart"];
//            NSString *deptId = [dict objectForKey:@"depart_id"];
//
//            self.tableViewDataSubtitle[indexPath.row] = deptName;
//            self.tableViewDataSubtitleId[indexPath.row] = deptId;
//
//            [self.tableView reloadData];
//
//        }
//    };
    
//    [self.navigationController pushViewController:deptview animated:YES];
    
    //UINavigationController *nv = [[UINavigationController alloc]initWithRootViewController:deptview];
    
    //[self.navigationController presentViewController:nv animated:YES completion:^{}];
    
}


@end
